<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: xywen
  Date: 2017/10/13
  Time: 14:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="row">
    <div class="col-sm-6">
        每页
        <select class="form-control" style="width:auto;display: initial;margin: 1px;">
            <option>20</option>
            <option>40</option>
        </select>
        条，共${param.totalElements}条
    </div>
    <div class="col-sm-6">
        <c:choose>
            <c:when test="${param.number - 5 gt 0}">
                <c:set var="bengin" value="${param.number - 5}"/>
            </c:when>
            <c:otherwise>
                <c:set var="bengin" value="0"/>
            </c:otherwise>
        </c:choose>
        <ul class="pagination pagination-sm no-margin pull-right" style="margin: 0px;">
            <li><a href="#"><span>&laquo;</span></a></li>
            <c:set var="endCount" value="${bengin + 9 }"/>
            <c:if test="${endCount > param.totalPages }">
            	<c:set var="endCount" value="${param.totalPages - 1 }"></c:set>
            </c:if>
            <c:forEach begin="${bengin}" end="${endCount}" varStatus="status">
                <c:choose>
                    <c:when test="${status.current eq param.number}">
                        <li class="active">
                            <span>${status.current + 1}</span>
                        </li>
                    </c:when>
                    <c:otherwise>
                        <li><a href="javascript:void(0);" data-page="${status.current}">${status.current +1}</a></li>
                    </c:otherwise>
                </c:choose>
            </c:forEach>
            <li>
                <a href="#">
                    <span>&raquo;</span>
                </a>
            </li>
        </ul>
    </div>
</div>
<script>
    $(document).ready(function(){
        $(".pagination a").on('click',function(){
            console.log(this);
            $("#contextForm input[name='page']").val($(this).data('page'))
            $("#contextForm").submit();
        })
    });
</script>
